//
//  SleepStagingResultV2.m
//  sr01sdkProject
//
//  Created by Linktop on 2022/8/16.
//

#import "SleepStagingResultV2.h"
#import "sleep_api.h"
#include "csem_api.h"

@implementation SleepStagingResultV2

- (instancetype)init:(NSNumber * _Nullable)avgHr RestHr:(NSNumber * _Nullable)restHr
{
    self = [super init];
    if (self) {
        self.averageHeartRate = avgHr;
        self.restingHeartRate = restHr;
    }
    return self;
}


/// 时间最长的睡眠
-(StagingDataV2 *)getLongestStagingData
{
    
    if (self.stagingDataList.count > 1) {
        __block StagingDataV2 * res = self.stagingDataList.firstObject;
        
        __block NSTimeInterval timeInterval = fabs(res.endTime - res.startTime) ;
        [self.stagingDataList enumerateObjectsUsingBlock:^(StagingDataV2 * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
           
            NSTimeInterval currentTimeInterval = fabs(obj.endTime - obj.startTime);
            if (timeInterval < currentTimeInterval) {
                timeInterval = currentTimeInterval;
                res = obj;
            }
        }];
        return res;
        
        
    }
    return self.stagingDataList.firstObject;
}


@end
